package cn.example.handlertest;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Main2Activity extends AppCompatActivity {

    private MyHandler myHandler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        myHandler=new MyHandler();
        myHandler.handler.sendEmptyMessage(1);
    }

    class MyHandler extends Thread{

        private Handler handler;
        @Override
        public void run() {
            Looper.prepare();//准备
            handler=new Handler(){
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                }
            };
            Looper.loop();//进行消息循环
        }
    }
}
